home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / Thread Manager Extension 1.2 / Interfaces / Think Pascal Interface (exp) / Threads.p (think Pascal vers)
Encoding:
Text File  |  1993-09-14  |  5.5 KB  |  195 lines  |  [TEXT/PJMM]

  1. {}
  2. {    File:        Threads.p}
  3. {}
  4. {    Contains:    External Interface to Thread Manager}
  5. {}
  6. {    Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.}
  7. {}
  8. {}
  9. {}
  10.  
  11. {$IFC UNDEFINED UsingIncludes}
  12. {$SETC UsingIncludes := 0}
  13. {$ENDC}
  14.  
  15. unit Threads;
  16. interface
  17.  
  18.     { UsingThreads }
  19.  
  20. { Thread Gestalt Selectors }
  21.     const
  22.         gestaltThreadMgrAttr = 'thds';                { Thread Manager attributes }
  23.         gestaltThreadMgrPresent = 0;                { bit true if Thread Mgr is present }
  24.         gestaltSpecificMatchSupport = 1;            { bit true if Thread Mgr supports exact match creation option }
  25.  
  26.  
  27. { Thread states }
  28.     type
  29.         ThreadState = INTEGER;
  30.  
  31.     const
  32.         kReadyThreadState = 0;
  33.         kStoppedThreadState = 1;
  34.         kRunningThreadState = 2;
  35.  
  36. { Thread environment characteristics }
  37.     type
  38.         ThreadTaskRef = Ptr;
  39.  
  40. { Thread characteristics }
  41.     type
  42.         ThreadStyle = LONGINT;
  43.  
  44.     const
  45.         kCooperativeThread = 1;
  46.         kPreemptiveThread = 2;
  47.  
  48. { Thread identifiers }
  49.     type
  50.         ThreadID = LONGINT;
  51.  
  52.     const
  53.         kNoThreadID = 0;
  54.         kCurrentThreadID = 1;
  55.         kApplicationThreadID = 2;
  56.  
  57. { Options when creating a thread }
  58.     type
  59.         ThreadOptions = LONGINT;
  60.  
  61.     const
  62.         kNewSuspend = 1;
  63.         kUsePremadeThread = 2;
  64.         kCreateIfNeeded = 4;
  65.         kFPUNotNeeded = 8;
  66.         kExactMatchThread = 16;
  67.  
  68. { Information supplied to the custom scheduler }
  69.     type
  70.         SchedulerInfoRecPtr = ^SchedulerInfoRec;
  71.         SchedulerInfoRec = record
  72.                 InfoRecSize: LONGINT;
  73.                 CurrentThreadID: ThreadID;
  74.                 SuggestedThreadID: ThreadID;
  75.                 InterruptedCoopThreadID: ThreadID;
  76.             end;
  77.  
  78. { Routine proc prototypes }
  79.     type
  80.     { Prototype for a thread's entry routine }
  81.         ThreadEntryProcPtr = ProcPtr;            { FUNCTION ThreadMain(threadParam: LONGINT): LONGINT; }
  82.  
  83.     { Prototype for a custom scheduler }
  84.         ThreadSchedulerProcPtr = ProcPtr;        { FUNCTION ThreadScheduler(schedulerInfo: SchedulerInfoRec): ThreadID; }
  85.  
  86.     { Prototype for a custom switcher }
  87.         ThreadSwitchProcPtr = ProcPtr;            { PROCEDURE ThreadSwitcher(threadBeingSwitched: ThreadID; switchProcParam: LONGINT); }
  88.  
  89.     { Prototype for a custom termination notification routine}
  90.         ThreadTerminationProcPtr = ProcPtr;        { PROCEDURE ThreadTerminator(threadTerminated: ThreadID; terminationProcParam: LONGINT); }
  91.  
  92.     { Prototypes for debugger new, dispose & schedule thread notification }
  93.         DebuggerNewThreadProcPtr = ProcPtr;            { PROCEDURE DebuggerNewThread(threadCreated: ThreadID); }
  94.         DebuggerDisposeThreadProcPtr = ProcPtr;        { PROCEDURE DebuggerDisposeThread(threadCreated: ThreadID); }
  95.         DebuggerThreadSchedulerProcPtr = ProcPtr;    { FUNCTION DebuggerThreadScheduler(schedulerInfo: SchedulerInfoRec): ThreadID; }
  96.  
  97.  
  98. { Errors }
  99.     const
  100.         threadTooManyReqsErr = -617;
  101.         threadNotFoundErr = -618;
  102.         threadProtocolErr = -619;
  103.  
  104.  
  105. { Thread Manager routines }
  106.     function CreateThreadPool (threadStylex: ThreadStyle; numToCreate: INTEGER; stackSize: Size): OSErr;
  107.     inline
  108.         $303C, $0501, $ABF2;
  109.  
  110.     function GetFreeThreadCount (threadStylex: ThreadStyle; var freeCount: INTEGER): OSErr;
  111.     inline
  112.         $303C, $0402, $ABF2;
  113.  
  114.     function GetSpecificFreeThreadCount ( threadStylex: ThreadStyle; stackSize: Size; VAR freeCount: INTEGER):OSErr;
  115.     inline
  116.         $303C, $0615, $ABF2;
  117.     
  118.     function GetDefaultThreadStackSize (threadStylex: ThreadStyle; var stackSize: Size): OSErr;
  119.     inline
  120.         $303C, $0413, $ABF2;
  121.  
  122.     function ThreadCurrentStackSpace (thread: ThreadID; var freeStack: LONGINT): OSErr;
  123.     inline
  124.         $303C, $0414, $ABF2;
  125.  
  126.     function NewThread (threadStylex: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: LONGINT; stackSize: Size; options: ThreadOptions; threadResult: LongIntPtr; var threadMade: ThreadID): OSErr;
  127.     inline
  128.         $303C, $0E03, $ABF2;
  129.  
  130.     function DisposeThread (threadToDump: ThreadID; threadResult: LONGINT; recycleThread: BOOLEAN): OSErr;
  131.     inline
  132.         $303C, $0504, $ABF2;
  133.  
  134.     function YieldToThread (suggestedThread: ThreadID): OSErr;
  135.     inline
  136.         $303C, $0205, $ABF2;
  137.  
  138.     function YieldToAnyThread: OSErr;
  139.     inline
  140.         $42A7, $303C, $0205, $ABF2;
  141.  
  142.     function GetCurrentThread (var currentThreadID: ThreadID): OSErr;
  143.     inline
  144.         $303C, $0206, $ABF2;
  145.  
  146.     function GetThreadState (threadToGet: ThreadID; var threadStatex: ThreadState): OSErr;
  147.     inline
  148.         $303C, $0407, $ABF2;
  149.  
  150.     function SetThreadState (threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  151.     inline
  152.         $303C, $0508, $ABF2;
  153.  
  154.     function SetThreadStateEndCritical (threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  155.     inline
  156.         $303C, $0512, $ABF2;
  157.  
  158.     function SetThreadScheduler (threadScheduler: ThreadSchedulerProcPtr): OSErr;
  159.     inline
  160.         $303C, $0209, $ABF2;
  161.  
  162.     function SetThreadSwitcher (thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: LONGINT; inOrOut: BOOLEAN): OSErr;
  163.     inline
  164.         $303C, $070A, $ABF2;
  165.  
  166.     function SetThreadTerminator (thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: LONGINT): OSErr;
  167.     inline
  168.         $303C, $0611, $ABF2;
  169.  
  170.     function ThreadBeginCritical: OSErr;
  171.     inline
  172.         $303C, $000B, $ABF2;
  173.  
  174.     function ThreadEndCritical: OSErr;
  175.     inline
  176.         $303C, $000C, $ABF2;
  177.  
  178.     function SetDebuggerNotificationProcs (notifyNewThread: DebuggerNewThreadProcPtr; notifyDisposeThread: DebuggerDisposeThreadProcPtr; notifyThreadScheduler: DebuggerThreadSchedulerProcPtr): OSErr;
  179.     inline
  180.         $303C, $060D, $ABF2;
  181.  
  182.     function GetThreadCurrentTaskRef (var threadTRef: ThreadTaskRef): OSErr;
  183.     inline
  184.         $303C, $020E, $ABF2;
  185.  
  186.     function GetThreadStateGivenTaskRef (threadTRef: ThreadTaskRef; threadToGet: ThreadID; var threadStatex: ThreadState): OSErr;
  187.     inline
  188.         $303C, $060F, $ABF2;
  189.  
  190.     function SetThreadReadyGivenTaskRef (threadTRef: ThreadTaskRef; threadToSet: ThreadID): OSErr;
  191.     inline
  192.         $303C, $0410, $ABF2;
  193.  
  194. implementation
  195. end.